const mongoose = require('mongoose')
const config = require('./db_url.js')

let options = config.mongodb.indexOf('localhost') !== -1 ? {} : {
  useMongoClient: true,
  auth: {
    authdb: 'admin',
    user: 'family_test1',
    password: 'EYiFR7LulYRHWkzy'
  }
};
module.exports = function () {
  const db = mongoose.connect(config.mongodb, options, function (err, db) {
    if (!err) { // 如果连接未出错
      console.log('数据库连接成功')
    } else {
      console.log(err)
    }
  })
  require('../model/user.js')
  require('../model/products.js')
  require('../model/feedback.js')
  return db
}
